<script>
import JSelectUserByDepModal from '../jeecgbiz/modal/JSelectUserByDepModal'
import { getUserList } from '@/api/api'
export default {
  name: 'XSelectUserByDepModal',
  mixins: [JSelectUserByDepModal],
  props:{
    userType:String
  },
  methods: {
    //获取选择用户信息
    getSelectUserRows(rowId) {
      let dataSource = this.dataSource
      let userIds = ''
      this.selectUserRows = []
      for (let i = 0, len = dataSource.length; i < len; i++) {
        if (this.selectedRowKeys.includes(dataSource[i].id)) {
          this.selectUserRows.push(dataSource[i])
          userIds = userIds + ',' + dataSource[i].id
        }
      }
      this.selectUserIds = userIds.substring(1)
    },
    initUserNames() {
      if (this.userIds) {
        // 这里最后加一个 , 的原因是因为无论如何都要使用 in 查询，防止后台进行了模糊匹配，导致查询结果不准确
        let values = this.userIds.split(',') + ','
        getUserList({
          id: values,
          pageNo: 1,
          pageSize: values.length
        }).then(res => {
          if (res.success) {
            let selectedRowKeys = []
            let realNames = []
            res.result.records.forEach(user => {
              realNames.push(user['realname'])
              selectedRowKeys.push(user['id'])
            })
            this.selectedRowKeys = selectedRowKeys
            this.$emit('initComp', realNames.join(','),selectedRowKeys.join(','),res.result.records)
          }
        })
      } else {
        // JSelectUserByDep组件bug issues/I16634
        this.$emit('initComp', '','','')
      }
    }
  }
}
</script>
